<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>添加渠道</title>
  <script src="https://cdn.jsdelivr.net/npm/babel-polyfill/dist/polyfill.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/jquery"></script>

  <link rel="stylesheet" href="__PUBLIC__/style/base.css">
  <link rel="stylesheet" href="__PUBLIC__/style/manage.css">
  <link rel="stylesheet" href="__PUBLIC__/node_modules/bootstrap/dist/css/bootstrap.min.css">
  <link rel="stylesheet" href="__PUBLIC__/style/qr_only.css">
</head>
<body>
  <div class="container-fluid">
    <div class="row">
      <header class="col-xs-6 col-md-2 account_name"><img class='img-responsive' src="__PUBLIC__/images/logo_long.jpg" alt=""></header>
      <div class="col-xs-12 col-md-12">
        <div class="row">

          <!-- 左侧栏 -->
          <div class="col-md-2 manage_nav_box">
            <iframe src="{:U('Wxauthorise/nav_1')}?local=qudao_a" frameborder="0" width="100%" style="height:35rem;"></iframe>
            <!-- 账号选项 -->
            <div class="account_option">
              <a href="{:U('index/update_passwd')}" class="pass_mod">修改密码</a>
              <a href="{:U('index/loginout')}" class="sign_out">退出登录</a>
            </div>
            <!-- end 账号选型 -->
          </div>
          <!-- end 左侧栏 -->

          <!-- 右主体  -->
          <div class="main">
            <!-- 渠道选择改动时会触发ajax，返回图片或者邀请码（用于生成code的URL也行） -->
            <input type="hidden" name="ajax_base" id="ajax_base" value = "{:U('Qudao/ajax_bank')}">
            <div class="title">扫码即可注册系统渠道</div>
            <div class="qr_code"><img id = 'qr_code_img' src="__PUBLIC__/images/5_0/u107.jpg" alt="qr_code"></div>
            <!-- <div class="refresh_qrcode"><button onclick="getQr()">刷新二维码</button></div> -->
          </div>
          <!-- <div class="wram_mess">刷新后先前二维码立刻失效</div> -->
          <!-- end 右主体 -->

        </div>
      </div>
    </div>
  </div>
  <script>
    function getQr () {
      const url = $('#ajax_base').val()
      // var name = $('#qudao_name').attr('name')
      // var bank_value = $('#qudao_name').val()
      // let bankData = {}
      // bankData[name] = bank_value
      $.ajax(url, {
        method: 'POST',
        data: '',
        success: function (data) {
          if( data.code === 1) {
            let url = data.message
            $('#qr_code_img').attr('src', url)
          } else {
            alert('二维码获取失败，请重新选择')
            $('#qudao_name').val('')
          }
        },
        error: function(){
          alert('二维码获取失败，请重新选择')
          $('#qudao_name').val('')
        }
      })
    }
    var url = $('#ajax_base').val()
    $(document).ready(function() {
      // $('#qudao_name').on('change', getQr)
      getQr()
    })

    window.addEventListener('message', fromNav, false)
    function fromNav(event) {
      console.log(event.data.url)
      if (event.data.url.length && event.data.url.length > 1) {
        self.location = event.data.url
      }
    }
  </script>
  <!-- <script src="__PUBLIC__/script/mock.js"></script> -->
</body>
</html>
